package com.yjhb.android.sbz.mvp.tipofflist;

import com.yjhb.android.sbz.entity.Report;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/12/22 15:33
 */
public class TipOffListPresenter extends ConventionPresenter<TipOffListView> {
    private final String TAG = "TipOffListPresenter";

    @Override
    protected void onDestroy() {

    }

    public TipOffListPresenter(TipOffListView tipOffListView) {
        super(tipOffListView);
    }


    public void getReportList(boolean isStart, int size, int current) {
        HttpTool.request(model.prosecutionList(isStart, size, current), new HttpObserver<List<Report>>() {
            @Override
            public void onResult(List<Report> data) {
                if (view != null) {
                    if (current == 1) {
                        view.onRefresh(data);
                    } else {
                        view.onLoad(data);
                    }
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });

    }

    /**
     * 撤销举报
     *
     * @param id
     */
    public void cancelReport(Integer id) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.prosecutionClose(id), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onCancel();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    /**
     * 通过任务
     * @param id
     */
    public void passTask(Integer id) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.auditAgain(id), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onTaskPass();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }
}
